package thread;

/**
 * 如果一个线程在等待监视器锁，被中断会怎样？
 */
public class ThreadInterruptDemo3 {
    public static void main(String[] args) throws InterruptedException {
        Object obj = new Object();
        Thread thread = new Thread(() -> {
            System.out.println("thread running");
            synchronized (obj) {
                System.out.println("thread get monitor");
                System.out.println("thread.state1 -> " + Thread.currentThread().getState());
                System.out.println("thread.isInterrupted -> " + Thread.currentThread().isInterrupted());
                Thread.interrupted();
            }
            System.out.println("thread exit");
        });
        synchronized (obj) {
            System.out.println("main get monitor");
            thread.start();
            Thread.sleep(1000);
            System.out.println("thread.state0 -> " + thread.getState());
            thread.interrupt();
            Thread.sleep(1000);
            System.out.println("main exit monitor");
        }
    }
}
